// Copyright (C) 2007 Dave Griffiths
// Licence: GPLv2 (see COPYING)
// Fluxus Shader Library
// ---------------------
// Wood Shader
// Cheezy procedural wood grain shader


varying vec3 N;
varying vec3 P;
varying vec3 V;
varying vec3 L;
    
void main()
{ 	    
    vec3 l = normalize(L);
    vec3 n = normalize(N);
    vec3 v = normalize(V);
    vec3 h = normalize(l+v);

    vec3 AmbientColour = vec3 (0.1, 0.1, 0.1);
    vec3 DiffuseColour1 = vec3 (0.8, 0.4, 0.1);
    vec3 DiffuseColour2 = vec3 (0.5, 0.1, 0.1);
    vec3 SpecularColour = vec3 (1.0, 1.0, 1.0);
    float AmbientIntensity = 1.0;
    float DiffuseIntensity = 1.0;
    float SpecularIntensity1 = 0.5;
    float SpecularIntensity2 = 1.0;
    float Roughness = 50.0;
    vec3 GrainCentre = vec3 (0.0, 2.0, 3.0);
    float GrainMult = 100.0;
	
    float d = length(P-GrainCentre);
    float g = clamp(sin(d*GrainMult),0.0,1.0);
  
    vec3 DiffuseColour = mix(DiffuseColour1,DiffuseColour2,g);
    float SpecularIntensity = mix(SpecularIntensity1,
                                  SpecularIntensity2,g);

    float diffuse = dot(l,n);
    float specular = pow(dot(n,h),1.0/Roughness);

    gl_FragColor = vec4(AmbientColour + DiffuseColour,1.0);
}
